package cn.edu.nuc.carsystem.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import cn.edu.nuc.carsystem.dto.PageInfo;
import cn.edu.nuc.carsystem.model.Bank;
import cn.edu.nuc.carsystem.model.City;
import cn.edu.nuc.carsystem.model.Company;
import cn.edu.nuc.carsystem.model.Conrtuny;
import cn.edu.nuc.carsystem.model.Price;
import cn.edu.nuc.carsystem.service.interfaces.BankService;
import cn.edu.nuc.carsystem.service.interfaces.CityService;
import cn.edu.nuc.carsystem.service.interfaces.CompanyService;
import cn.edu.nuc.carsystem.service.interfaces.PriceService;
/**
 * 公司controller
 * @author 杨晓庆
 *
 */
@RequestMapping("/car/company")
@Controller
public class CompanyController {
   @Autowired
   private CompanyService companyService;
   /**
    * 添加担保
    * @param price
    * @return
    */
   @RequestMapping(value="/insert",method=RequestMethod.POST)
	public String insert(Company company,HttpSession session){
    Integer count=companyService.insert(company,session);
    if(count>0){
	   return "redirect:/car/company/findAll";
    }
    else
       return "/car/company/addcompany";
   }
   /**
    * 跳转添加担保页面
    * @param price
    * @return
    */
   @RequestMapping(value="/addCompany",method=RequestMethod.GET)
	public String addBank(){
   
       return "car/addcompany";
   }
   /**
    * 分页查询所有担保
    * @param current
    * @return
    */
   @RequestMapping(value="/findAll",method=RequestMethod.GET)
  	public ModelAndView findAll(@RequestParam(name="current",defaultValue="1") Integer current,Company company){
     ModelAndView model=new ModelAndView("car/companylist");
      PageInfo pi=companyService.findAll(company,current);
      model.addObject("pi",pi);
      System.out.println("length"+pi.getItem().size());
      System.out.println("companylist"+pi);
  	  return model;
  	}
   /**
    * 分页查询所有担保,用户页面显示
    * @param current
    * @return
    */
   @RequestMapping(value="/User/findAll",method=RequestMethod.GET)
  	public ModelAndView UserfindAll(@RequestParam(name="current",defaultValue="1") Integer current,Company company){
     ModelAndView model=new ModelAndView("custome/companylist");
      PageInfo pi=companyService.findAll(company,current);
      model.addObject("pi",pi);
      System.out.println("length"+pi.getItem().size());
      System.out.println("companylist"+pi);
  	  return model;
  	}
   /**
    * 请求修改页面
    * @param comid
    * @return
    */
   @RequestMapping(value="/updateCompany",method=RequestMethod.GET)
  	public ModelAndView updateCompany(Integer comid){
	   System.out.println("comid"+comid);
        ModelAndView model=new ModelAndView("car/updatecompany");
        Company company=companyService.selectByPrimaryKey(comid);
       System.out.println("companyupdates"+company);
        model.addObject("company",company);
         return   model;
     }
   /**
    * 修改公司信息
    * @param company
    * @return
    */
   @RequestMapping(value="/update",method=RequestMethod.POST)
 	public String update(Company company,HttpSession session){
    
       Integer count=companyService.updateByPrimaryKeySelective(company,session);
      
        return   "redirect:/car/company/findAll";
    }

}
